package com.atnjupt.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Wizarder
 * @create 2021-06-09 16:39
 */
public class LoginServlet extends BaseServlet{
    protected void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //获取请求的参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        if("luhu".equals(username)&&"123456".equals(password)){
            Cookie cookie = new Cookie("username",username);
            cookie.setMaxAge(60*60*24);
            response.addCookie(cookie);
            request.getRequestDispatcher("/cookie.html").forward(request,response);
        }else{
            request.getRequestDispatcher("/login.jsp").forward(request,response);
        }
    }
}
